$().ready(function(){
	//初始化排序條件
	init();
});
//改变排序条件
function sortByMethod(sortByField){
	$("#sortBy").val(sortByField);
	if ( "shelfPrice" == sortByField ){
		if ( $("#orderByPrice").val() == "" || $("#orderByPrice").val() == "desc" ){
			$("#orderBy").val("asc");
			$("#orderByPrice").val("asc");
		}else if ( $("#orderByPrice").val() == "asc" ){
			$("#orderBy").val("desc");
			$("#orderByPrice").val("desc");
		}
	}
	if ( "startDate" == sortByField ){
		if ( $("#orderByDate").val() == "" || $("#orderByDate").val() == "desc" ){
			$("#orderBy").val("asc");
			$("#orderByDate").val("asc");
		}else if ( $("#orderByDate").val() == "asc" ){
			$("#orderBy").val("desc");
			$("#orderByDate").val("desc");
		}
	}
	$("#categoryForm").submit();
	return false;
}
//初始化排序條件
function init(){
	if ( $("#sortBy").val() == "shelfPrice" ){
		if ( $("#orderByPrice").val() == "desc" )
			$("#shelfPrice").attr("class","filterbtn-2-down-f");
		else if ( $("#orderByPrice").val() == "asc" )
			$("#shelfPrice").attr("class","filterbtn-2-up-f");
		
		if ( $("#orderByDate").val() == "desc" )
			$("#startDate").attr("class","filterbtn-4-down");
		else if ( $("#orderByDate").val() == "asc" )
			$("#startDate").attr("class","filterbtn-4-up");
	}

	if ( $("#sortBy").val() == "startDate" ){
		if ( $("#orderByDate").val() == "desc" )
			$("#startDate").attr("class","filterbtn-4-down-f");
		else if ( $("#orderByDate").val() == "asc" )
			$("#startDate").attr("class","filterbtn-4-up-f");
		
		if ( $("#orderByPrice").val() == "desc" )
			$("#shelfPrice").attr("class","filterbtn-2-down");
		else if ( $("#orderByPrice").val() == "asc" )
			$("#shelfPrice").attr("class","filterbtn-2-up");
	}
}	